package com.xuxiao.service.impl;

import com.xuxiao.common.CardAndBalance;
import com.xuxiao.common.CartAndName;
import com.xuxiao.common.NameAndCardID;
import com.xuxiao.entrty.CardInfo;
import com.xuxiao.mapper.CardInfoMapper;
import com.xuxiao.service.CardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class CardInfoServiceImpl implements CardInfoService {
    @Autowired
    private CardInfoMapper cardInfoMapper;

    @Override
    public void addCard(CardInfo cardInfo) {
        cardInfo.setOpenDate(LocalDate.now());
        cardInfoMapper.insertCard(cardInfo);
    }

    @Override
    public List<CartAndName> SelectAll() {
        return cardInfoMapper.SelectAll();
    }

    @Override
    public List<CardInfo> SelectByID(String id) {
        return cardInfoMapper.SelectByID(id);
    }

    @Override
    public void DeleteCardByID(List<Integer> ids) {
        cardInfoMapper.DeleteAll(ids);
    }

    @Override
    public void updateCardBy(CardInfo cardInfo) {
        cardInfoMapper.updateCardBy(cardInfo);
    }

    @Override
    public List<CardInfo> getCardByUserID(String id) {
        return cardInfoMapper.getCardByUserID(id);
    }

    @Override
    public void plusByCard(CardInfo cardInfo) {
        cardInfoMapper.plusByCard(cardInfo);
    }

    @Override
    public List<CardAndBalance> getAllCartBalance(String id) {
        return cardInfoMapper.getAllCartBalance(id);
    }

    @Override
    public List<NameAndCardID> getNameAndCardID(String id) {
        return cardInfoMapper.getNameAndCardID(id);
    }

    @Override
    public int IsCorrect(CardInfo cardInfo) {
        return cardInfoMapper.IsCorrect(cardInfo);
    }
}
